package com.example.music;

import android.content.Intent;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.Log;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;

public class WebViewActivity extends AppCompatActivity {

    private WebView webView;
    String query;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);

        webView = findViewById(R.id.webView);

        // 启用JavaScript支持
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        Intent intent = getIntent();
        if (intent != null) {
            query = intent.getStringExtra("query");
            if (query != null) {
                // 处理接收到的数据
                Log.e("接收到的query", query);
            }
        }

        // 加载网页
        String url = "https://www.gequbao.com/s/"+query;
//        String url = "http://119.91.196.247:7778/y/index.html";
        Log.e("网页搜索URL",url);
        webView.loadUrl(url);
    }

    @Override
    public void onBackPressed() {
        // 处理WebView的后退操作
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }
}
